using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml;

namespace Coffee.SurveyControls.SurveyQuestions
{


    /// <summary>
    /// Summary description for SQListBox
    /// </summary>
    public class SQListBox : SurveyQuestionRow
    {
        public SQListBox(SurveyControl parent, XmlNode configuration)
            : base(parent, configuration)
        {
        }


        public override void LoadDynamicData()
        {
            ListBox lbcurr = (ListBox)currentAnswerControl;
            Coffee.Binding.ConfigureBinding(lbcurr, rootNode);
            lbcurr.DataBind();
        }

        public override void LoadData()
        {
            Label tPrev = (Label)previousAnswerControl;
            ListBox lbcurr = (ListBox)currentAnswerControl;

            string current = ctlId;
            string currentype = "";

            if (rootNode.SelectSingleNode("mapping/current") != null)
            {
                currentype = rootNode.SelectSingleNode("mapping/current").Attributes["type"].Value;
                current = rootNode.SelectSingleNode("mapping/current/text()").Value;
            }
            if (Parent.Mapper != null)
            {
                tPrev.Text = (string)Parent.Mapper.Previous.GetProperty(ctlId);

                if (currentype == "index")
                    lbcurr.SelectedIndex = (int)Parent.Mapper.Current.GetProperty(current);
                else
                    lbcurr.SelectedValue = (string)Parent.Mapper.Current.GetProperty(current);
            }
        }

        public override void SaveData()
        {
            //throw new Exception("Not Implemented");
            if (Parent.Mapper != null)
            {
            }
        }

        protected override void Initialize()
        {

            Label tprev = new Label();
            ListBox dcurr = new ListBox();

            tprev.CssClass = "question";
            dcurr.CssClass = "big-textBoxes";

            Coffee.Binding.Map(dcurr, rootNode, "properties/set");

            previousAnswerControl = tprev;
            currentAnswerControl = dcurr;


            prevCell.Controls.Add(previousAnswerControl);
            currCell.Controls.Add(currentAnswerControl);
        }

        protected override Control CreateCurrentDataControl()
        {
            throw new NotImplementedException();
        }

        protected override Control CreatePreviousDataControl()
        {
            throw new NotImplementedException();
        }

    }
}